home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_061 / microemacs / ibmpc.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  7KB  |  349 lines

  1. /*
  2.  * The routines in this file provide support for the IBM-PC and other
  3.  * compatible terminals. It goes directly to the graphics RAM to do
  4.  * screen output. It compiles into nothing if not an IBM-PC driver
  5.  */
  6.  
  7. #define    termdef    1            /* don't define "term" external */
  8.  
  9. #include        <stdio.h>
  10. #include    "estruct.h"
  11. #include        "edef.h"
  12.  
  13. #if     IBMPC
  14.  
  15. #define NROW    25                      /* Screen size.                 */
  16. #define NCOL    80                      /* Edit if you want to.         */
  17. #define    MARGIN    8            /* size of minimim margin and    */
  18. #define    SCRSIZ    64            /* scroll size for extended lines */
  19. #define    NPAUSE    200            /* # times thru update to pause */
  20. #define BEL     0x07                    /* BEL character.               */
  21. #define ESC     0x1B                    /* ESC character.               */
  22. #define    SPACE    32            /* space character        */
  23.  
  24. #define    SCADC    0xb8000000L        /* CGA address of screen RAM    */
  25. #define    SCADM    0xb0000000L        /* MONO address of screen RAM    */
  26.  
  27. #define    CDCGA    0            /* color graphics card        */
  28. #define    CDMONO    1            /* monochrome text card        */
  29. #define    CDSENSE    9            /* detect the card type        */
  30.  
  31. int dtype = CDCGA;            /* current display type        */
  32. long scadd;                /* address of screen ram    */
  33. int *scptr[NROW];            /* pointer to screen lines    */
  34. int sline[NCOL];            /* screen line image        */
  35. extern union REGS rg;            /* cpu register for use of DOS calls */
  36.  
  37. extern  int     ttopen();               /* Forward references.          */
  38. extern  int     ttgetc();
  39. extern  int     ttputc();
  40. extern  int     ttflush();
  41. extern  int     ttclose();
  42. extern  int     ibmmove();
  43. extern  int     ibmeeol();
  44. extern  int     ibmeeop();
  45. extern  int     ibmbeep();
  46. extern  int     ibmopen();
  47. extern    int    ibmrev();
  48. extern    int    ibmcres();
  49. extern    int    ibmclose();
  50. extern    int    ibmputc();
  51. extern    int    ibmkopen();
  52. extern    int    ibmkclose();
  53.  
  54. #if    COLOR
  55. extern    int    ibmfcol();
  56. extern    int    ibmbcol();
  57.  
  58. int    cfcolor = -1;        /* current forground color */
  59. int    cbcolor = -1;        /* current background color */
  60. int    ctrans[] =        /* ansi to ibm color translation table */
  61.     {0, 4, 2, 6, 1, 5, 3, 7};
  62. #endif
  63.  
  64. /*
  65.  * Standard terminal interface dispatch table. Most of the fields point into
  66.  * "termio" code.
  67.  */
  68. TERM    term    = {
  69.     NROW-1,
  70.         NROW-1,
  71.         NCOL,
  72.         NCOL,
  73.     MARGIN,
  74.     SCRSIZ,
  75.     NPAUSE,
  76.         ibmopen,
  77.         ibmclose,
  78.     ibmkopen,
  79.     ibmkclose,
  80.         ttgetc,
  81.     ibmputc,
  82.         ttflush,
  83.         ibmmove,
  84.         ibmeeol,
  85.         ibmeeop,
  86.         ibmbeep,
  87.     ibmrev,
  88.     ibmcres
  89. #if    COLOR
  90.     , ibmfcol,
  91.     ibmbcol
  92. #endif
  93. };
  94.  
  95. extern union REGS rg;
  96.  
  97. #if    COLOR
  98. ibmfcol(color)        /* set the current output color */
  99.  
  100. int color;    /* color to set */
  101.  
  102. {
  103.     cfcolor = ctrans[color];
  104. }
  105.  
  106. ibmbcol(color)        /* set the current background color */
  107.  
  108. int color;    /* color to set */
  109.  
  110. {
  111.         cbcolor = ctrans[color];
  112. }
  113. #endif
  114.  
  115. ibmmove(row, col)
  116. {
  117.     rg.h.ah = 2;        /* set cursor position function code */
  118.     rg.h.dl = col;
  119.     rg.h.dh = row;
  120.     rg.h.bh = 0;        /* set screen page number */
  121.     int86(0x10, &rg, &rg);
  122. }
  123.  
  124. ibmeeol()    /* erase to the end of the line */
  125.  
  126. {
  127.     int attr;    /* attribute byte mask to place in RAM */
  128.     int *lnptr;    /* pointer to the destination line */
  129.     int i;
  130.     int ccol;    /* current column cursor lives */
  131.     int crow;    /*       row    */
  132.  
  133.     /* find the current cursor position */
  134.     rg.h.ah = 3;        /* read cursor position function code */
  135.     rg.h.bh = 0;        /* current video page */
  136.     int86(0x10, &rg, &rg);
  137.     ccol = rg.h.dl;        /* record current column */
  138.     crow = rg.h.dh;        /* and row */
  139.  
  140.     /* build the attribute byte and setup the screen pointer */
  141. #if    COLOR
  142.     if (dtype == CDCGA)
  143.         attr = (((cbcolor & 15) << 4) | (cfcolor & 15)) << 8;
  144.     else
  145.         attr = 0x0700;
  146. #else
  147.     attr = 0x0700;
  148. #endif
  149.     lnptr = &sline[0];
  150.     for (i=0; i < term.t_ncol; i++)
  151.         *lnptr++ = SPACE | attr;
  152.  
  153.     if (flickcode) {
  154.         /* wait for vertical retrace to be off */
  155.         while ((inp(0x3da) & 8))
  156.             ;
  157.     
  158.         /* and to be back on */
  159.         while ((inp(0x3da) & 8) == 0)
  160.             ;
  161.     }            
  162.  
  163.     /* and send the string out */
  164.     movmem(&sline[0], scptr[crow]+ccol, (term.t_ncol-ccol)*2);
  165.  
  166. }
  167.  
  168. ibmputc(ch)    /* put a character at the current position in the
  169.            current colors */
  170.  
  171. int ch;
  172.  
  173. {
  174.     rg.h.ah = 14;        /* write char to screen with current attrs */
  175.     rg.h.al = ch;
  176. #if    COLOR
  177.     if (dtype == CDCGA)
  178.         rg.h.bl = cfcolor;
  179.     else
  180.         rg.h.bl = 0x07;
  181. #else
  182.     rg.h.bl = 0x07;
  183. #endif
  184.     int86(0x10, &rg, &rg);
  185. }
  186.  
  187. ibmeeop()
  188. {
  189.     int attr;        /* attribute to fill screen with */
  190.  
  191.     rg.h.ah = 6;        /* scroll page up function code */
  192.     rg.h.al = 0;        /* # lines to scroll (clear it) */
  193.     rg.x.cx = 0;        /* upper left corner of scroll */
  194.     rg.x.dx = 0x184f;    /* lower right corner of scroll */
  195. #if    COLOR
  196.     if (dtype == CDCGA)
  197.         attr = ((ctrans[gbcolor] & 15) << 4) | (ctrans[gfcolor] & 15);
  198.     else
  199.         attr = 0;
  200. #else
  201.     attr = 0;
  202. #endif
  203.     rg.h.bh = attr;
  204.     int86(0x10, &rg, &rg);
  205. }
  206.  
  207. ibmrev(state)        /* change reverse video state */
  208.  
  209. int state;    /* TRUE = reverse, FALSE = normal */
  210.  
  211. {
  212.     /* This never gets used under the IBM-PC driver */
  213. }
  214.  
  215. ibmcres(res)    /* change screen resolution */
  216.  
  217. char *res;    /* resolution to change to */
  218.  
  219. {
  220.     if (strcmp(res, "CGA") == 0) {
  221.         scinit(CDCGA);
  222.         return(TRUE);
  223.     } else if (strcmp(res, "MONO") == 0) {
  224.         scinit(CDMONO);
  225.         return(TRUE);
  226.     } else
  227.         return(FALSE);
  228. }
  229.  
  230. ibmbeep()
  231. {
  232. #if    MWC86
  233.     putcnb(BEL);
  234. #else
  235.     bdos(6, BEL, 0);
  236. #endif
  237. }
  238.  
  239. ibmopen()
  240. {
  241.     scinit(CDSENSE);
  242.     revexist = TRUE;
  243.         ttopen();
  244. }
  245.  
  246. ibmclose()
  247.  
  248. {
  249. #if    COLOR
  250.     ibmfcol(7);
  251.     ibmbcol(0);
  252. #endif
  253.     ttclose();
  254. }
  255.  
  256. ibmkopen()    /* open the keyboard */
  257.  
  258. {
  259. }
  260.  
  261. ibmkclose()    /* close the keyboard */
  262.  
  263. {
  264. }
  265.  
  266. scinit(type)    /* initialize the screen head pointers */
  267.  
  268. int type;    /* type of adapter to init for */
  269.  
  270. {
  271.     union {
  272.         long laddr;    /* long form of address */
  273.         int *paddr;    /* pointer form of address */
  274.     } addr;
  275.     int i;
  276.  
  277.     /* if asked...find out what display is connected */
  278.     int86(0x11, &rg, &rg);
  279.     dtype = CDCGA;
  280.     scadd = SCADC;
  281.     strcpy(sres, "CGA");
  282.     if ((((rg.x.ax >> 4) & 11) == 3) || type == CDMONO) {
  283.         strcpy(sres, "MONO");
  284.         dtype = CDMONO;
  285.         scadd = SCADM;
  286.     }
  287.  
  288.     /* initialize the screen pointer array */
  289.     for (i = 0; i < NROW; i++) {
  290.         addr.laddr = scadd + (long)(NCOL * i * 2);
  291.         scptr[i] = addr.paddr;
  292.     }
  293. }
  294.  
  295. scwrite(row, outstr, forg, bacg)    /* write a line out*/
  296.  
  297. int row;    /* row of screen to place outstr on */
  298. char *outstr;    /* string to write out (must be term.t_ncol long) */
  299. int forg;    /* forground color of string to write */
  300. int bacg;    /* background color */
  301.  
  302. {
  303.     int attr;    /* attribute byte mask to place in RAM */
  304.     int *lnptr;    /* pointer to the destination line */
  305.     int i;
  306.  
  307.     /* build the attribute byte and setup the screen pointer */
  308. #if    COLOR
  309.     if (dtype == CDCGA)
  310.         attr = (((ctrans[bacg] & 15) << 4) | (ctrans[forg] & 15)) << 8;
  311.     else
  312.         attr = (((bacg & 15) << 4) | (forg & 15)) << 8;
  313. #else
  314.     attr = (((bacg & 15) << 4) | (forg & 15)) << 8;
  315. #endif
  316.     lnptr = &sline[0];
  317.     for (i=0; i<term.t_ncol; i++)
  318.         *lnptr++ = (outstr[i] & 255) | attr;
  319.  
  320.     if (flickcode) {
  321.         /* wait for vertical retrace to be off */
  322.         while ((inp(0x3da) & 8))
  323.             ;
  324.     
  325.         /* and to be back on */
  326.         while ((inp(0x3da) & 8) == 0)
  327.             ;
  328.     }
  329.  
  330.     /* and send the string out */
  331.     movmem(&sline[0], scptr[row],term.t_ncol*2);
  332. }
  333.  
  334. #if    FLABEL
  335. fnclabel(f, n)        /* label a function key */
  336.  
  337. int f,n;    /* default flag, numeric argument [unused] */
  338.  
  339. {
  340.     /* on machines with no function keys...don't bother */
  341.     return(TRUE);
  342. }
  343. #endif
  344. #else
  345. ibmhello()
  346. {
  347. }
  348. #endif
  349.